package trabajoISW2.tests;

import java.util.LinkedList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import trabajoISW2.domain.contracts.IPublisher;
import trabajoISW2.domain.exceptions.WrongIdException;
import trabajoISW2.domain.exceptions.WrongNameException;
import trabajoISW2.domain.implementations.Book;


public class PublisherTestSuite {
	
	IPublisher p;
	List<Book> books;
	Book b1, b2;
	SuperTest st;
	@Before
	public void setup(){
		st = new SuperTest();
		st.inicializa();
		p = st.publisher1;
		books = new LinkedList<Book>();
		b1 = st.book1;
		b2 = st.book2;
	}
	
	//Tests setPublisherId
	@Test
	public void testSetPublisherId(){
		p.setPublisherId(0);
		p.setPublisherId(1);
		p.setPublisherId(Integer.MAX_VALUE);
		p.setPublisherId(Integer.MAX_VALUE-1);
	}
	
	@Test(expected = WrongIdException.class)
	public void testSetPublisherId1(){
		p.setPublisherId(-1);
	}
	
	@Test(expected = WrongIdException.class)
	public void testSetPublisherId2(){
		p.setPublisherId(Integer.MIN_VALUE);
	}
	
	@Test(expected = WrongIdException.class)
	public void testPublisherId3(){
		p.setPublisherId(Integer.MIN_VALUE+1);
	}
	
	//Tests setName
	@Test
	public void testSetName(){
		p.setName("prueba");
				
	}
	
	@Test(expected = WrongNameException.class)
	public void testSetName1(){
		p.setName(null);
	}
	@Test(expected = WrongNameException.class)
	public void testSetName2(){
		p.setName("");
	}
	
	//Tests setBooks
	
	@Test
	public void testSetBook(){
		
		p.setBooks(books);
		books.add(b1);
		p.setBooks(books);
		books.add(b2);
		p.setBooks(books);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testSetBook1(){
		p.setBooks(null);
	}
	
	
	//Tests addBook
	
	@Test
	public void testAddBook(){
		p.addBook(b1);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testAddBook1(){
		p.addBook(null);
	}
	
	//Tests removeBook
	
	@Test
	public void testRemoveBook(){
		p.removeBook(b1);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testRemoveBook1(){
		p.removeBook(null);
	}

}
